namespace Brjnk.Maps
{
    using System;
    using System.Threading;

    public class Timer : ITimer
    {
        public event Action Elapsed;

        private System.Threading.Timer tmr;

        public Timer()
        {
            tmr = new System.Threading.Timer(new System.Threading.TimerCallback(OnElpased), null, Timeout.Infinite, Timeout.Infinite);
        }

        public void Change(long dueTime, long period)
        {
            if (dueTime < 0) dueTime = Timeout.Infinite;
            if (period < 0) dueTime = Timeout.Infinite;
            tmr.Change(dueTime, period);
        }

        private void OnElpased(object state)
        {
            if (Elapsed != null) Elapsed();
        }
    }
}